﻿var strRootPath = window.document.location.protocol + "//" + window.document.location.host + "/";
function addShopCart(numberID, productID, price) {
    var regxQty = /^(([1-9]\d*)|0)(\.)?(\d{1,4})?$/;
    var qty = $.trim($("#" + numberID).val());
    if (regxQty.test(qty)) {

        var vll = $.ajax({
            url: strRootPath + "handler/addShopCart.ashx?id=" + productID + "&qty=" + qty + "&date=" + new Date(),
            async: false
        }).responseText;
        if (vll.split(';')[0] == "1") {
            alert("添加成功！");
        }
        else {
            alert(vll.split(';')[1]);
            if (vll.split(';')[0] == "2") {
                location.href = "../user/login.aspx";
            }
        }
    }
    else {
        alert("购买数量格式不对！");
    }
}

function checkQty(id) {
    var regxQty = /^(([1-9]\d*)|0)(\.)?(\d{1,4})?$/;
    var qty = id.value; //  $.trim($("#" + id).val());
    if (qty == "") {
        return;
    }
    if (!regxQty.test(qty)) {
        alert("购买数量格式不对！");
    }
}
$(document).ready(function () {
    $(".intInput").bind("keydown", function () { checkDigitInput(this, event, 1, 0) });
    $(".intInput").bind("paste", function () { return !clipboardData.getData('text').match(/\D/) });
    $(".intInput").bind("dragenter", function () { return false });
});
function checkDigitInput(el, ev, isInt, isNeg) {
    var event = ev || window.event;
    var currentKey = event.charCode || event.keyCode;
    if (event.shiftKey == true) {
        if (window.event)
            event.returnValue = false;
        else
            event.preventDefault();
    }
    else {
        if (currentKey == 110 || currentKey == 190) {
            if (isInt == 1) {
                if (window.event)
                    event.returnValue = false;
                else
                    event.preventDefault();
            }
            else {
                if (el.value.indexOf(".") >= 0)
                    if (window.event)
                        event.returnValue = false;
                    else
                        event.preventDefault();
            }
        } else
            if (currentKey == 189 || currentKey == 109) {
                if (isNeg == 1) {
                    if (getPos(el) > 0 || el.value.indexOf("-") >= 0)
                        if (window.event)
                            event.returnValue = false;
                        else
                            event.preventDefault();
                }
                else {
                    if (window.event)
                        event.returnValue = false;
                    else
                        event.preventDefault();
                }
            } else {
                if (currentKey != 8 && currentKey != 9 && currentKey != 46 && (currentKey < 37 || currentKey > 40) && (currentKey < 48 || currentKey > 57) && (currentKey < 96 || currentKey > 105))
                    if (window.event)
                        event.returnValue = false;
                    else
                        event.preventDefault();
            }
    }

}
